﻿namespace ExcelPlugin {
    using System.Collections.Generic;
    using System.Reflection;
    using Excel = Microsoft.Office.Interop.Excel;

    #region global_config
    static class FILE_PATH {
        public static readonly string XML_COMMON_DEFINE = "common_define.xml";
    }
    static class WS_PATH {
        public static readonly string WS_PATH_SOURCE = "source\\";
        public static readonly string WS_PATH_CONFIG = "config\\";
#if DEBUG
        public static readonly string WS_PATH_PREFIX = "ws_test\\";
#else
        public static readonly string WS_PATH_PREFIX = "toolws\\";
#endif
    }
    static class XML_ATTR_NAME {
        public const string NAME = "name";
        public const string VALUE = "value";
        public const string KEY = "key";
        public const string TYPE = "type";
        public const string TYPE_PARAM = "type_param";
        public const string DESC = "desc";
        public const string COUNT = "count";
        public const string PRIMARY = "primary";
        public const string TBNAME = "tablename";
        public const string VALID = "valid";
        public const string MODE = "mode";
    }
    static class XML_ELEMENTS_NAME {
        //解析XML时统一使用本组常量解析
        public const string CONST = "const";
        public const string ENUM = "enum";
        public const string CLASS = "class";
        public const string SUBCLASS = "subclass";
        public const string GROUP = "group";
        public const string DATASOURCE = "data_source";
        public const string ENTRY = "entry";

        public const string VALID = "validations";
        public const string REF = "ref";
    }
    static class XML_DATA_TYPE_NAME {
        //转换Excel数据时才使用本组定义的类型概念
        public static readonly string INT = "int";
        public static readonly string STR = "string";
        public static readonly string ENUM = "enum";
        public static readonly string SUBCLASS = "subclass";
        public static readonly string GROUP = "group";
        public static readonly string CLASS = "class";

        public static bool CheckTypeValid(string type) {
            FieldInfo[] fields = typeof(XML_DATA_TYPE_NAME).GetFields();
            foreach(FieldInfo item in fields) {
                string name = (string)item.GetValue(null);
                if(string.Compare(name, type) == 0) {
                    return true;
                }
            }
            return false;
        }
        //检查是否是基础类型
        public static bool IsBaseType(string type) {
            if(type == INT || type == STR) {
                return true;
            }
            return false;
        }
        //检测主键的配置类型，只有int和string可以作为主键
        public static bool PrimaryKeyType(string type) {
            if(type == INT || type == STR || type == ENUM) {
                return true;
            }
            return false;
        }
    }
    public enum JSON_MODE {
        CLIENT = 1,
        SERVER = 1 << 1,
        COMMON = CLIENT | SERVER,
    }
    #endregion

    #region global_param
    public static class GlobalBlackBoard {
        public static string cur_wb_relative_path = string.Empty;

        private static Dictionary<string, Excel.Workbook> m_curOpenWB = new Dictionary<string, Excel.Workbook>();
        public static Dictionary<string, Excel.Workbook> CurOpenWB
        {
            get { return m_curOpenWB; }
        }
        public static void AddWBFullName(string name, Excel.Workbook wb) {
            if(m_curOpenWB.ContainsKey(name)) {
                return;
            }
            m_curOpenWB.Add(name, wb);
        }
        public static void RemoveWBFullName(string fullName) {
            if(m_curOpenWB.ContainsKey(fullName)) {
                m_curOpenWB.Remove(fullName);
            }
       }
    }
    #endregion

}
